<template>
	<div class="record-info">
		<van-tabs v-model:active="tabState.active" animated sticky swipeable>
			<van-tab v-for="item in tabState.list" :title="item.title" :name="item.value" :key="item.value">
				<component
					:is="+route.query.type === 1 ? buildingDetail : buildingDetail2"
					v-if="+tabState.active === 1"
					:baseData="data?.baseData"
					:collectionData="data?.collectionData"
          :locationInfo="data?.locationInfo"
				/>
				<component
					:is="+route.query.type === 1 ? checkDataDetail : checkDataDetail2"
					v-if="+tabState.active === 2"
					:detail="data?.checkData"
				/>
			</van-tab>
		</van-tabs>
	</div>
</template>

<script setup>
import { checkLogInfo, buildingBase } from '@/service/village'
import { onMounted, reactive } from 'vue'
import { useRoute } from 'vue-router'
import buildingDetail from './components/buildingDetail'
import checkDataDetail from './components/checkDataDetail'

import buildingDetail2 from '@/views/inspection/components/buildingDetail'
import checkDataDetail2 from '@/views/inspection/components/checkDataDetail'

const route = useRoute()
const tabState = reactive({
	active: 1,
	list: [
		{ title: '房屋信息', value: 1 },
		{ title: '检查信息', value: 2 },
	]
})

const booleanKey = [
	'wdwhjgfjgqsyyrkrgbdj',
	'sstdsyyrkrclzx',
	'gryssdcsszblyyqksddp',
	'cjzwqtjyyt',
	'fwyfwdddzxccdsssfayqjshsf',
	'sfszsszsbzhaqckbz',
	'sfazfztsss',
]
const haveOrNotKey = [
	// 'ywgdlttxwd',
]
const haveEnum = {
	1: '有',
	0: '无'
}
const booleanEnum = {
	2: '不涉及',
	1: '是',
	0: '否'
}

const data = reactive({
	baseData: {},
	collectionData: {},
	checkData: {},
  locationInfo: {}
})

const getCheck = async () => {
	const result = await checkLogInfo({
		id: route.query.id
	})
	if (result?.succ) {
		data.baseData = {
			...result?.data.zmPcBase,
			region: `${result?.data?.zmPcBase?.xzqname}-${result?.data?.zmPcBase?.townname}-${result?.data?.zmPcBase?.villagename}`
		}
    data.locationInfo = {
      address: result?.data?.zmPcBase?.currentLocation,
      lng: result?.data?.zmPcBase?.longitude,
      lat: result?.data?.zmPcBase?.latitude,
    }
		data.checkData = result?.data?.zmPcYh || {}
		data.collectionData = result?.data?.zmPcBase || {}
		booleanKey.map(item => {
			data.collectionData[item] = booleanEnum[result?.data?.zmPcBase?.[item]]
		})
		haveOrNotKey.map(item => {
			data.collectionData[item] = haveEnum[result?.data?.zmPcBase?.[item]]
		})
	}
}

onMounted(() => {
	getCheck()
	tabState.list[1].title = +route.query.type === 1 ? '检查信息' : '自查信息'
})
</script>

<style scoped lang="less">
.record-info {

}
</style>
